/********************************************************************************
* @File name: led.c
* @Author: Loganx
* @Blog: https://www.cnblogs.com/loganxiang
* @Version: 1.0(2025-10-09)
* @Description: STC8A单片机LED控制程序，可以实现点亮、熄灭或以不同的周期闪烁
********************************************************************************
* 本软件使用了STC的STC8A官方库；
********************************************************************************/
#include "led.h"

uint8 LEDMode;
uint8 LEDFlashCycle;

void LEDSetMode(uint8 mode){
    LEDMode = mode;

    switch(mode){
        case(LED_MODE_OFF):
            LED = FALSE;
            break;
        case(LED_MODE_ON):
            LED = TRUE;
            break;
        case(LED_MODE_FLASH_1S):
            LEDFlashCycle = 10;
            break;
        case(LED_MODE_FLASH_2S):
            LEDFlashCycle = 20;
            break;
        case(LED_MODE_FLASH_5S):
            LEDFlashCycle = 10;
            break;
        default:
            break;
    }
}

//Systick callback(100ms)
void SystickCallbackLED(void){
    static uint8 i = 0;
    
    if(LEDMode & 0x02){
        if(++i > 2)
            LED = FALSE;
        if(i > LEDFlashCycle){
            i = 0;
            LED = TRUE;
        }
    }
}